/**
 * 控制订单管理面的数据的显示
 * 2017-11-2
 */
$(function () {  
       //初始化第一页数据；  
        var urlApi = 'https://jindi163.com:8443/JDLot/admin/paynum/add';
        var d=new Date(); 
        var day=d.getDate() ;//查看Date对象并返回日期 
　　		var month=d.getMonth()+1; 
		var yy=d.getFullYear();
		var endtime=yy+"01"+"01"+"000000";//去年
　      	var times=yy+1+"01"+"01"+"000000"; //今年
	var phone=sessionStorage.getItem("phone");
	 $("#serch").click(function(){//天的查询
   times=$("#first_data_li").val();
   times=times.replace(/-/g,"");
   
   if (times=="") {
   	times="";
   	endtime=$("#first_data").val();
   endtime=endtime.replace(/-/g,"");
   endtime=parseInt(endtime)+"000000";
   } else{
   	endtime=$("#first_data").val();
   endtime=endtime.replace(/-/g,"");
   times=parseInt(times)+"235959";
   endtime=parseInt(endtime)+"000000";
   }
   
   $('.movieList').empty();
console.log(times+"  "+endtime)
   isshows();
	})
	  $("#serch_one").click(function(){
		   	times=$("#first_data_one_li").val();
		    endtime=$("#first_data_one").val();
		    console.log(times)
		    if(times==""){
		    times="";
		    endtime=endtime.replace(/-/g,"");
		 	endtime=parseInt(endtime)+"01010000";
		    }
		    else{
		    times=times.replace(/-/g,"");
		    endtime=endtime.replace(/-/g,"");
		   	times=parseInt(times)+"01235959";
		 	endtime=parseInt(endtime)+"01010000";
		    }
		   
//console.log(endtime+"-----"+times)
 	$('.movieList').empty();  
   isshows();
	})
	   $("#serch_two").click(function(){
   times=$("#first_data_two").val();
   endtime=times; 
   times=parseInt(times)+1+"01"+"01"+"000000";
 	endtime=endtime+"01"+"01"+"000000";
    console.log(endtime+"........"+times)
    $('.movieList').empty();
   isshows();
	})
	isshows()
	function isshows(){
        $.ajax({  
            url:urlApi,  
            type:'post',  
            dataType:'json',
            contentType:"application/json",
            async:true,
            cache:false,
            data: {
            	"startTime":endtime,
				"endTime":times,
//				"phone":phone,			//管理员的手机号码
				"PageSize":"10",//每页显示数据长度
				"PageNum":"1"
            },//参数配置：
            xhrFields: {
   						 withCredentials: true
						},
					crossDomain: true,
            success:function(msg){  
            //total总条数属性，计算总页数
            	console.log(msg);
				var  total= msg.totalPage;//显示页数
              	var  result  = msg.datas;  
//              console.log(result);  
				$('.movieList').empty();
                var str='<li class="masg_lis" style="color:red"><span>支付时间</span><span>用户账号</span><span>支付方式</span><span style="width:16%">商品名称</span><span>订单号</span><span>实际支付</span><span>每笔订单的收入</span></li>';  
                var sums_pirce=0;
                $(".wrap .pps").remove();
                for(var i=0;i<result.length;i++){
		                    var item = result[i];
//		                    console.log(item)
		                    var sum=0;
		                    //判断是否为支付宝---微信
		                    if(item.pay_type=="支付宝"){
		                    	sum=(item.receipt_amount)*0.9994;
		                    	sum=sum.toFixed(2)
		                    }else{
		                    	sum=(item.receipt_amount)*0.9994*0.9994;
		                    	sum=sum.toFixed(2)
		                    	
		                    }
                	
                	sums_pirce=parseFloat(sums_pirce)+parseFloat(sum);
                	
                  //获得年月日      得到日期oTime  
//	getMyDate(item.gmt_payment)
//	
//      function getMyDate(sstr){    
            var oDate = new Date(item.gmt_payment),    
            oYear = oDate.getFullYear(),    
            oMonth = oDate.getMonth()+1,    
            oDay = oDate.getDate(),    
            oHour = oDate.getHours(),    
            oMin = oDate.getMinutes(),    
            oSen = oDate.getSeconds(),    
            oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +'-'+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间    
            oTimes = oYear +''+ getzf(oMonth) +''+ getzf(oDay) +''+ getzf(oHour) +''+ getzf(oMin) +''+getzf(oSen);//最后拼接时间 
//         console.log(oTime);    
//      };    
        //补0操作    
        function getzf(num){    
            if(parseInt(num) < 10){    
                num = '0'+num;    
            }    
            return num;    
        }  
                    		str +=	'<li class="masg_lis"><span>'+oTime+
                    				'</span><span>'+item.uphono+
		                    		'</span><span>'+item.pay_type+
		                    		'</span><span  style="width:16%">'+item.subject+
		                    		'</span><span>'+oTimes+
		                    		'</span><span>'+item.receipt_amount+
		                    		
		                    		'</span><span>'+sum+
		                    		'</span></li>';  
		                    		
                }  
                //追加渲染到页面  
                $('.movieList').append(str)  
              sums_pirce=sums_pirce.toFixed(2);
                var htl='<span class="pps" style="position:relative;bottom:3rem;right:-5rem;font-size:2rem">本页收入:'+sums_pirce+'</span>';
               	$(".wrap").append(htl);
                
                //分页插件，  
                $(".tcdPageCode").createPage({  
                    //pageCount：总页数  
                    pageCount:total,  
                    //current：当前页  默认第一页
                    current:1,  
                    backFn:function(pageIndex){  
                    //单击回调方法，pageIndex是当前页码  
                        $(".movieList").empty();  
                        var start =pageIndex;//开始的页码数

 
                       			$.ajax({  
			                            url:urlApi,  
			                            type:'post',  
			                            dataType:'json', 
			                            contentType:"application/json",
							            async:true,
							            cache:false,
			                           data: {
						            	"startTime":endtime,
										"endTime":times,
//										"phone":phone,//管理员的手机号码
										"PageSize":10,//每页显示数据长度
										"PageNum":start
										},
										xhrFields: {
   						 withCredentials: true
						},
					crossDomain: true,
			                            beforeSend: function(XMLHttpRequest) {
			                              $("body").append(
                                            '<div id="aaaa" style="z-index:999;position:fixed; top:0;left:0;right:0;bottom:0;margin:auto;width:100%;height:100%">'+
                                            '<div  id="load" style="z-index:666; position:fixed; top:0;left:0;right:0;bottom:0;margin:auto;width:4rem;height:4rem">'+
			                                '<img alt="数据加载中..." src="../img/4c3ba25d7384dee10d565e7f20c89400_t014be238bb089e1e42.gif" style="width:100%"/></div></div>');
			                                 },  
			                            success:function(data){
			                            		console.log(data)
				                                var result  = data.datas;
				                                
				                                $('.movieList').empty();
				                                 var str1='<li class="masg_lis" style="color:red"><span>支付时间</span><span>用户账号</span><span>支付方式</span><span>商品名称</span><span>订单号</span><span>实际支付</span><span>每笔订单的收入</span></li>';  
               var sums_pirce=0;
                for(var i=0;i<result.length;i++){
		                    var item = result[i]; 
		                    var sum=0;
		                    //判断是否为支付宝---微信
		                    if(item.pay_type=="支付宝"){
		                    	sum=(item.receipt_amount)*0.9994;
		                    	sum=sum.toFixed(2)
		                    }else{
		                    	sum=(item.receipt_amount)*0.9994*0.9994;
		                    	sum=sum.toFixed(2)
		                    	
		                    }
                	
                	sums_pirce=parseFloat(sums_pirce)+parseFloat(sum);
		var oDate = new Date(item.gmt_payment),    
            oYear = oDate.getFullYear(),    
            oMonth = oDate.getMonth()+1,    
            oDay = oDate.getDate(),    
            oHour = oDate.getHours(),    
            oMin = oDate.getMinutes(),    
            oSen = oDate.getSeconds(),    
            oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +'-'+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间    
            oTimes = oYear +''+ getzf(oMonth) +''+ getzf(oDay) +''+ getzf(oHour) +''+ getzf(oMin) +''+getzf(oSen);//最后拼接时间 
//         console.log(oTime);    
//      };    
        //补0操作    
        function getzf(num){    
            if(parseInt(num) < 10){    
                num = '0'+num;    
            }    
            return num;    
        }  
                    		str1 +=	'<li class="masg_lis"><span>'+oTime+	
                    				'</span><span>'+item.uphono+
		                    		'</span><span>'+item.pay_type+
		                    		'</span><span>'+item.subject+
		                    		'</span><span>'+oTimes+
		                    		'</span><span>'+item.receipt_amount+
		                    		'</span><span>'+sum+
		                    		'</span></li>';  
                }  
                //追加渲染到页面  
                $('.movieList').append(str1);
								 $(".wrap .pps").remove();
								 sums_pirce=sums_pirce.toFixed(2);
                var htls='<span class="pps" style="position:relative;bottom:3rem;right:-5rem;font-size:2rem">本页收入:'+sums_pirce+'</span>';
               	$(".wrap").append(htls);
			                            } ,
			     						complete: function(XMLHttpRequest, textStatus) {$("#aaaa").remove(); 
			     					}  
			                        }) 
			                  
                    			}  
                			});  
            			},
//    					complete: function(XMLHttpRequest, textStatus) {$("#aaaa").remove(); 
//    				},
      				error:function(error){
            	alert("请求数据失败！")
            }, 
       			}) 
       		}
    })  
